package com.modules.system.controller;


import java.io.IOException;

import com.modules.system.dto.LoginDto;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.base.Return;
import com.shiro.ShiroUtils;

/**
 * 登录相关
 *
 * @author linhengming
 * @date 2018年01月25日 下午1:55:58
 */
@Controller
public class LoginController {
	/**
	 * 登录
	 */
	@ResponseBody
	@RequestMapping(value = "/sys/login", method = RequestMethod.POST)
	public Return login(@RequestBody LoginDto user )throws IOException {
		Subject subject = ShiroUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(),user.getPassword());
		subject.login(token);
		return Return.success();
	}

	/**
	 * 退出
	 */
	@ResponseBody
	@RequestMapping(value = "/sys/logout", method = RequestMethod.GET)
	public Return logout() {
		ShiroUtils.logout();
		return Return.success();
	}

}
